package greedy;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class wiggleMaxLength {
    public int wiggleMaxLength(int[] nums) {
        int result = 0;
        int flag = 0;
        if (nums.length == 0){
            return result;
        }
        for (int i = nums.length - 1; i > 0; i--) {
            if (nums[i] == nums[i-1]){
                continue;
            }
            if (flag == 0){
                if (nums[i] > nums[i-1]){
                    flag = 1;
                    result++;
                }
                if (nums[i] < nums[i-1]){
                    flag = -1;
                    result++;
                }
            }else if (flag == 1){
                if (nums[i] < nums[i-1]){
                    flag = -1;
                    result++;
                }
            } else {
                if (nums[i] > nums[i-1]){
                    flag = 1;
                    result++;
                }
            }
        }
        return result + 1;
    }
}
